
class People {
    name: string;
    age: number;
    addr: string;
    static count: number = 0
    constructor(_name: string, _age: number, _addr: string) {
        this.name = _name;
        this.age = _age;
        this.addr = _addr;
        People.count++;
    }
    doEat(who: string, where: string) {
        console.log(`who:${who},where:${where}`);

    }
    doStep() {

    }
}

class StringUile {
    static trimSpace(str: string) {
        return str.replace(/\s+/g, "")
    }
}

const dataProp1 = Object.getOwnPropertyDescriptor(People.prototype, "doEat")
// const dataProp2 = Object.getOwnPropertyDescriptor(People.prototype,"doStep")
// console.log(dataProp1===dataProp2);

const targetMethod = dataProp1!.value
dataProp1!.value = function (...args: any[]) {
    args = args.map(arg => {
        if (typeof arg === 'string') {
            return StringUile.trimSpace(arg)
        }
        return arg
    })
    console.log("前置拦截");
    targetMethod.apply(this, args)
    console.log("后置拦截");

}
// dataProp1?.value("亡命","王府井")
Object.defineProperty(People.prototype, "doEat", dataProp1!)

let p = new People('Peter', 23, "北京")
p.doEat('张 三', '东 西')

export { }